package fightplan.actions;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;

public abstract class UndoableAction extends AbstractAction {
	private UndoRedoManagerProvider managerProvider;
	@SuppressWarnings("unused")
	private String undoText, redoText;

	public UndoableAction(String name, UndoRedoManagerProvider managerProvider, String undoText) {
		this(name, managerProvider, undoText, name);
	}

	public UndoableAction(String name, UndoRedoManagerProvider managerProvider, String undoText, String redoText) {
		super(name);
		this.managerProvider = managerProvider;
		this.undoText = undoText;
		this.redoText = redoText;
	}

	public final void actionPerformed(ActionEvent actionEvent) {
		managerProvider.getUndoRedoManager().createMemento(undoText);
		if (!doAction(actionEvent)) {
			managerProvider.getUndoRedoManager().recallMemento();
		}
		// Redo wird zur Zeit nicht unterstützt
		// managerProvider.getUndoRedoManager().completeMemento(redoText);
	}

	protected abstract boolean doAction(ActionEvent actionEvent);

}
